#include "CTestUtil.h"
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkDataSetMapper.h>
#include <vtkPolyData.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkClipClosedSurface.h>
#include <vtkPlane.h>
#include <vtkPlaneCollection.h>
#include <vtkSTLReader.h>

void CTestUtil::read(const QString &name)
{
    vtkSmartPointer<vtkSTLReader> reader=vtkSTLReader::New();
    reader->SetFileName(name.toLocal8Bit().data());
    reader->Update();
    polyData=reader->GetOutput();
}

void CTestUtil::test()
{

    double *center = polyData->GetCenter();
      vtkSmartPointer<vtkPlane> plane1 =
        vtkSmartPointer<vtkPlane>::New();
      plane1->SetOrigin(center[0], center[1], center[2]);
      plane1->SetNormal(0.0, -1.0, 0.0);
      vtkSmartPointer<vtkPlane> plane2 =
        vtkSmartPointer<vtkPlane>::New();
      plane2->SetOrigin(center[0], center[1], center[2]);
      plane2->SetNormal(0.0, 0.0, 1.0);
      vtkSmartPointer<vtkPlane> plane3 =
        vtkSmartPointer<vtkPlane>::New();
      plane3->SetOrigin(center[0], center[1], center[2]);
      plane3->SetNormal(-1.0, 0.0, 0.0);

      vtkSmartPointer<vtkPlaneCollection> planes =
        vtkSmartPointer<vtkPlaneCollection>::New();
      planes->AddItem(plane1);
      planes->AddItem(plane2);
      planes->AddItem(plane3);

      vtkSmartPointer<vtkClipClosedSurface> clipper =
        vtkSmartPointer<vtkClipClosedSurface>::New();
      clipper->SetInputData(polyData);
      clipper->SetClippingPlanes(planes);
      clipper->SetActivePlaneId(2);
      clipper->SetScalarModeToColors();
      clipper->SetClipColor(0.8900, 0.8100, 0.3400); // banana
      clipper->SetBaseColor(1.0000, 0.3882, 0.2784); // tomato
      clipper->SetActivePlaneColor(0.6400, 0.5800, 0.5000); // beige

      vtkSmartPointer<vtkDataSetMapper> clipMapper =
        vtkSmartPointer<vtkDataSetMapper>::New();
      clipMapper->SetInputConnection(clipper->GetOutputPort());
      polyMapper=clipMapper;
}
